import React from 'react'
import { Modal, Button, Form, Input, Select, Table, message, } from 'antd'
import OrderFilterUnExpand from 'components/Filter/OrderFilterUnExpand'
import LwjTable from 'components/LwjTable/LwjTable'
import { contractOrderType, contractOrderStatus } from 'utils/enumConfig'
import moment from 'moment';
import _default from 'antd/lib/date-picker';

const ContractTableModal = ({items, dispatch, changeType, ...contractTableModalProps}) => {

  const tableProps = {
    dataSource: items,
    pagination: false,
    loading: false,
    columns: [{
      title: '合同编号',
      key: 'contractNum',
      dataIndex: 'contractNum',
    }, {
      title: '合同类型',
      dataIndex: 'contractOrderType',
      key: 'contractOrderType',
      render: (text, record) => (
        <span>
            {contractOrderType[text]}
          </span>
      )
    }, {
      title: '客户信息',
      dataIndex: 'customerName',
      key: 'customerName',
      render: (text, record) => (
        <span>
            {record.customerName}/{record.customerPhoneNum}
          </span>
      )
    }, {
      title: '收货人信息',
      dataIndex: 'consigneeName',
      key: 'consigneeName',
      render: (text, record) => (
        <span>
            {record.consigneeName}/{record.consigneePhoneNum}
          </span>
      )
    }, {
      title: '合同状态',
      dataIndex: 'status',
      key: 'status',
      render: (text, record) => (
        <span>
            {contractOrderStatus[text]}
          </span>
      )
    }, {
      title: '下单时间',
      dataIndex: 'createTime',
      key: 'createTime',
      render: (text, record, index) => (moment(text).format("YYYY-MM-DD HH:mm:ss"))
    },],
    selectType: 'single',
    selectedRowKeys: contractTableModalProps.selectedRowKeys,
    onSelectRows: (a, b) => {
      /** @namespace b.canChange */
      if (b[0].canChange !== true) {
        message.error('这个订单不能进行修改')
        return
      }
      dispatch({
        type: 'contractOrders/setContractSelectedRowKeys',
        payload: a
      })
    }
  }

  /**
   * 定义筛选属性 表单相关
   * @type {{filterItems: *[], onFilterChange(*): void}}
   */
  const filterProps = {
    filterItems: [
      {
        type: 'input',
        id: 'contractNum',
        title: '合同号'
      }
    ],
    onFilterChange (value) {
      if(_.isEmpty(value)){
        Modal.error({
          title:"错误",
          content: "请输入合同号！"
        })
        return
      }
      dispatch({
        type: 'contractOrders/changeList',
        payload: {
          ...value,
          contractChangeType: changeType
        }
      })
    },
    noExpandButton:"noExpand"
  }

  return (
    <Modal {...contractTableModalProps}>
      <OrderFilterUnExpand {...filterProps} />
      <LwjTable {...tableProps}/>
    </Modal>
  )
}

export default ContractTableModal
